import { createRouter, createWebHashHistory } from "vue-router";

const routes = [
  {
    path: "/",
    redirect: { path: "/layout/home" }, // 重定向到首页
  },
  {
    path: "/layout",
    name: "layout",
    component: () => import("@/layout/index.vue"), // 布局组件
    children: [
      {
        path: "home",
        name: "home",
        component: () => import("@/views/layout/home/index.vue"),
        meta: { name: "首页", requiresAuth: false }, // 要求用户登录才能访问
      },
      {
        path: "workbench",
        name: "workbench",
        component: () => import("@/views/layout/workbench/index.vue"),
        meta: { name: "工作台", requiresAuth: false }, // 要求用户登录才能访问
      },
      {
        path: "profile",
        name: "profile",
        component: () => import("@/views/layout/profile/index.vue"),
        meta: { name: "个人中心", requiresAuth: true }, // 要求用户登录才能访问
      },
    ],
  },
  {
    path: "/login",
    name: "login",
    component: () => import("@/views/login/index.vue"),
  },
  {
    path: "/:pathMatch(.*)*",
    name: "NotFound",
    component: () => import("@/views/error/404.vue"),
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});

export default router;
